package com.xunqi.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunqi.crm.mapper.UserMapper;
import com.xunqi.crm.pojo.User;
import com.xunqi.crm.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User findUserByName(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("usr_name",name);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public User login(String name,String pwd) {
        User user = findUserByName(name);
        if (user != null && user.getUsrPassword().equals(pwd)){
            return user;
        }
        return null;
    }

    @Override
    public IPage<User> selectPage(long currPage, long pageSize, Wrapper<User> wrapper) {
        Page<User> page = new Page<>(currPage,pageSize);

        IPage<User> userIPage = userMapper.selectPage(page,wrapper);

        return  userIPage;
    }

}
